package com.auto.tools;

import com.auto.oa.org.domain.OaOrgInfo;
import com.auto.oa.org.service.OaOrgServiceFactory;
import com.auto.oa.user.domain.OaUserInfo;
import com.auto.oa.user.domain.OaUserInfoExtend;
import com.auto.oa.user.service.OaUserServiceFactory;
import com.system.util.BeanUtil;
import com.system.util.SessionUtil;

public class AutoUtils {
	
	/**
	 * 获取登录用户帐号
	 * @return
	 */
	public static String getUserCode(){
//		String userCode = SessionUtil.getCurrentUserLabel();
		String userCode = "admin";
		
		return userCode;
	}
	
	/**
	 * 获取用户姓名
	 * @param userCode	登录帐号
	 * @return
	 * @throws Exception
	 */
	public static String getUserName(String userCode) throws Exception{
		if(BeanUtil.isNotBlank(userCode)){
			OaUserInfo oaUserInfo = OaUserServiceFactory.oaUserInfoService.getOaUserInfoByUserCode(userCode);
			String userName = oaUserInfo.getAuserName();
			
			return userName;
		}else{
			throw new NullPointerException("用户工号为空，无法获取用户姓名");
		}
	}
	
	/**
	 * 获取用户组织代码
	 * @param userCode	用户帐号
	 * @return
	 * @throws Exception
	 */
	public static String getUserOrgCode(String userCode) throws Exception{
		if(BeanUtil.isNotBlank(userCode)){
			OaUserInfoExtend oaUserInfoExtend = OaUserServiceFactory.oaUserInfoService.getUserOrg(userCode);
			String orgCode = oaUserInfoExtend.getAuorgCode();
			
			return orgCode;
		}else{
			throw new NullPointerException("用户工号为空，无法获取用户姓名");
		}
	}
	
	/**
	 * 获取组织名称
	 * @param orgCode	组织代码
	 * @return
	 * @throws Exception
	 */
	public static String getUserOrgName(String orgCode) throws Exception{
		if(BeanUtil.isNotBlank(orgCode)){
			OaOrgInfo oaOrgInfo = OaOrgServiceFactory.oaOrgInfoService.getOaOrgInfoByOrgCode(orgCode);
			String orgName = oaOrgInfo.getAuorgName();
			
			return orgName;
		}else{
			throw new NullPointerException("用户工号为空，无法获取用户姓名");
		}
	}

}
